package com.example.demo7.dao.impl;

import com.example.demo7.dao.SysLogDao;
import com.example.demo7.domain.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;


@Repository
public class SysLogDaoImp implements SysLogDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @Override
    public void saveSysLog(SysLog syslog) {
//
//        sql.append("(id,username,operation,time,method,params,ip,create_time) ");
//        sql.append("values(seq_sys_log.nextval,:username,:operation,:time,:method,");
//        sql.append(":params,:ip,:createTime)");
//      INSERT INTO `sys_log` VALUES (1, 'aLinxi', 'hhh', 1111, 'save', 'username', '127.0.0.1', '2022-01-05 00:00:00');


        StringBuffer sql = new StringBuffer("insert into sys_log ");
        sql.append("values(syslog.getId(),syslog.getUsername(),syslog.getOperation(),syslog.getTime(),syslog.getMethod(),syslog.getParams(),syslog.getIp(),syslog.getCreateTime()")
        System.out.println(this.jdbcTemplate.getDataSource());
        NamedParameterJdbcTemplate npjt = new NamedParameterJdbcTemplate(this.jdbcTemplate.getDataSource());
        npjt.update(sql.toString(), new BeanPropertySqlParameterSource(syslog));
    }
}